package eppic.pkg;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import android.widget.EditText;
import android.content.*;





public class CreateClientActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.createclient);
        
      //Do Rate
        EditText rate = (EditText) findViewById(R.id.rate);
        rate.setText("$0.00");
        rateTextWatcher rateWatcher = new rateTextWatcher(this, rate);
        rate.addTextChangedListener(rateWatcher);
    }
    
    
    public void goBack(View view) {
    	finish();
    }
    
    public void submitClient(View view)
    {
    	
    	String company = ((EditText) findViewById(R.id.companyname)).getText().toString();
    	String clientname = ((EditText) findViewById(R.id.contactname)).getText().toString();
    	
    	//rate
    	int string_start = 0;
    	String rate_string = ((EditText) findViewById(R.id.rate)).getText().toString();
    	if(rate_string.substring(0,1).equals("$"))
    		string_start = 1;
    	float rate = new Float(rate_string.substring(string_start, rate_string.length()));
    	
    	String email = ((EditText) findViewById(R.id.email)).getText().toString();
    	String phone = ((EditText) findViewById(R.id.phone)).getText().toString();
    	String notes = ((EditText) findViewById(R.id.notes)).getText().toString();
    	
    	
    	Client client = new Client(company, clientname, rate, email, phone, notes );
    	
    	if(client.save(getApplicationContext()))
    	{
    		Toast.makeText(getApplicationContext(), "Client Saved", Toast.LENGTH_SHORT).show();
    		finish();
    	}
    	else
    	{
    		Toast.makeText(getApplicationContext(), "Failed to Save Client. Try Again.", Toast.LENGTH_SHORT).show();
    	}

    }

    
}